<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/tags.jsp"%>
<%@ page import="java.util.*"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title></title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta content="noindex, nofollow" name="robots" />
<script src="common/fck_dialog_common.js" type="text/javascript"></script>
<ww:bean name="cn.myapps.core.dynaform.form.action.FormHelper" id="fh">
	<ww:param name="moduleid" value="#parameters.moduleid" />
</ww:bean>
<html>
<o:MultiLanguage>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href='<ww:url value="/resource/css/main.css" />' type="text/css">
<ww:bean name="cn.myapps.core.dynaform.view.action.ViewHelper"
	id="viewHelper">
	<ww:param name="moduleid" value="#parameters.moduleid" />
</ww:bean>
<link href="../css/dialog.css" rel="stylesheet" type="text/css" />
<script src='<ww:url value="/dwr/engine.js"/>'></script>
<script src='<ww:url value="/dwr/util.js"/>'></script>
<script src='<ww:url value="/dwr/interface/FormHelper.js"/>'></script>
<script src='<ww:url value="/dwr/interface/Sequence.js"/>'></script>
<script language="JavaScript" src="dialog.js"></script>
<script language="JavaScript" src="script.js"></script>
<script language="JavaScript" src="sequence.js"></script>

<script type="text/javascript">

var dialog	= window.parent ;
var oEditor = dialog.InnerDialogLoaded() ;

// Gets the document DOM
var oDOM = oEditor.FCK.EditorDocument ;

var oActiveEl = dialog.Selection.GetSelectedElement() ;

window.onload = function()
{
	// First of all, translate the dialog box texts
	oEditor.FCKLanguageManager.TranslatePage(document) ;
	//InitDocument();

	if ( oActiveEl && oActiveEl.tagName == 'INPUT' && ( oActiveEl.type == 'text' || oActiveEl.type == 'password' ) )
	{
		GetE('name').value	= oActiveEl.name ;
		GetE('borderType').value	= oActiveEl.value ;
		//GetE('txtSize').value	= GetAttribute( oActiveEl, 'size' ) ;
		//GetE('txtMax').value	= GetAttribute( oActiveEl, 'maxLength' ) ;
		GetE('discript').value	= oActiveEl.type ;
	}
	else
		oActiveEl = null ;

	dialog.SetOkButton( true ) ;
	dialog.SetAutoSize( true ) ;
	SelectField( 'name' ) ;
}

function Ok(){
    var isok=true;
	//检查内容是否完成正确
	for(var i=0;i<document.all("editMode").length;i++){
		   if(document.all("editMode")[i].checked){
		    if(document.all("editMode")[0].checked){
		     isok=createItems();
		     if(!isok){
		         return false;
		     }
		      temp.valueScript.value="";
		    }else{
		      temp.processDescription.value="";
		      temp.filtercondition.value="";
		    }
		  
	      }
	  }
	if(!ev_check())
		return false;
	
	if(sAction == "modify"){
		oControl.name = temp.name.value;
		oControl.refreshOnChanged = temp.refreshOnChanged.checked+"";
		oControl.borderType = getBorderType();
		oControl.calculateOnRefresh = temp.calculateOnRefresh.checked+"";
		oControl.discript = temp.discript.value;
		oControl.valueScript = HTMLEncode(temp.valueScript.value);
		oControl.validateRule = HTMLEncode(temp.validateRule.value);
		oControl.hiddenScript = HTMLEncode(temp.hiddenScript.value);
		oControl.hiddenPrintScript = HTMLEncode(temp.hiddenPrintScript.value);
		oControl.readonlyScript = HTMLEncode(temp.readonlyScript.value);
		oControl.fieldtype = temp.fieldtype.options[temp.fieldtype.selectedIndex].value;
		oControl.textType = temp.textType.options[temp.textType.selectedIndex].value;
		oControl.fieldkeyevent = temp.fieldkeyevent.options[temp.fieldkeyevent.selectedIndex].value;
		oControl.numberPattern = HTMLEncode(temp.numberPattern.value);
		oControl.processDescription = createRelStr();
	    oControl.filtercondition=document.temp.filtercondition.value;
		oControl.authority = document.all('authority').checked+"";
		oControl.mobile = document.all('mobile').checked+""; 
		for(var i=0;i<document.all("editMode").length;i++){
		   if(document.all("editMode")[i].checked){
		  
		   oControl.editMode=document.all("editMode")[i].value;
	      }
	    }
		if(oControl.id==null||oControl.id=='')
		{
		  oControl.id = getFieldId();
		}
		var validateLibs=document.getElementsByName('validateLibs');
	       var libs='';
	       for(var i=0; i< validateLibs.length; i++){
   			if(validateLibs[i].checked){
   				libs+=validateLibs[i].value+';';
   			}
   			}
   		   libs=libs.substring(0,libs.length-1);
	   	   oControl.validateLibs=libs;

	//}
	//else if(dialogArguments != null) {
  		//dialogArguments.insertHTML(getInnerHTML());
  		
	}

	oEditor.FCKUndo.SaveUndoStep() ;

	oActiveEl = CreateNamedElement( oEditor, oActiveEl, 'INPUT', {name: GetE('name').value, type: GetE('borderType').value } ) ;

	SetAttribute( oActiveEl, 'value'	, GetE('naem').value ) ;
	//SetAttribute( oActiveEl, 'size'		, GetE('txtSize').value ) ;
	//SetAttribute( oActiveEl, 'maxlength', GetE('txtMax').value ) ;
	return true;
}
function Ok1()
{
	/*
	if ( isNaN( GetE('name').value ) || GetE('name').value < 0 )
	{
		alert( "Maximum characters must be a positive number." ) ;
		GetE('name').focus();
		return false ;
	}
	else if( isNaN( GetE('borderType').value ) || GetE('borderType').value < 0 )
	{
		alert( "Width must be a positive number." ) ;
		GetE('borderType').focus() ;
		return false ;
	}
	
	oEditor.FCKUndo.SaveUndoStep() ;

	oActiveEl = CreateNamedElement( oEditor, oActiveEl, 'INPUT', {name: GetE('name').value,name:GetE('borderType').value,name:GetE('discript').value} ) ;

	SetAttribute( oActiveEl, 'name'	, GetE('name').value ) ;
	SetAttribute( oActiveEl, 'borderType'		, GetE('borderType').value ) ;
	SetAttribute( oActiveEl, 'discript', GetE('discript').value ) ;
	*/
	return true ;
}

function HTMLEncode(text){
	text = text.replace(/&/g, "@amp;") ; 
	text = text.replace(/"/g, "@quot;") ;
	text = text.replace(/</g, "@lt;") ;
	text = text.replace(/>/g, "@gt;") ;
	text = text.replace(/'/g, "@#146;") ;
	text = text.replace(/\ /g,"@nbsp;");
	return text;
}

// 替换特殊字符
function HTMLDencode(text){
	var textold;
	do {
		textold = text;
		text = text.replace("@amp;","&") ;
		text = text.replace('@quot;','"') ;
		text = text.replace("@lt;","<") ;
		text = text.replace("@gt;",">") ;
		text = text.replace("@#146;","'") ;
		text = text.replace("@nbsp;"," ");
        }
        while(textold != text);
	return text;
}

function cardClick(cardID){
	var obj;
	for (var i=1;i<7;i++){
		obj=document.all("card"+i);
		obj.style.backgroundColor="#3A6EA5";
		obj.style.color="#FFFFFF";
	}
	obj=document.all("card"+cardID);
	obj.style.backgroundColor="#FFFFFF";
	obj.style.color="#3A6EA5";

	for (var i=1;i<7;i++){
		obj=document.all("content"+i);
		obj.style.display="none";
	}
	obj=document.all("content"+cardID);
	obj.style.display="";

	//resize();
}

function getBorderType(){
	  var value= '';
	  var borderType = document.getElementsByName('borderType');
	  if(borderType.length>0){
		  for(var i=0;i<borderType.length;i++){
			  if(borderType[i].checked){
			     value = borderType[i].value;
			  }
		  }
	  }
	  return value;
	}

	function initBorderType(value){
	  var borderType = document.getElementsByName('borderType');
	  if(borderType.length>0){
		  for(var i=0;i<borderType.length;i++){
			  if(value == "true"){
			     borderType[1].checked=true;
			  }else{
			     borderType[0].checked=true;
			  }
		  }
	  }
	}

	function getInnerHTML() {
		var s = '<input className="cn.myapps.core.dynaform.form.ejb.InputField"';
		s += ' type="text" ';
		s += ' name="'+HTMLEncode(temp.name.value)+'"';
		s += ' id = "'+getFieldId()+'"';
		s += ' refreshOnChanged="'+HTMLEncode(temp.refreshOnChanged.checked+"")+'"';
		s += ' calculateOnRefresh="'+HTMLEncode(temp.calculateOnRefresh.checked+"")+'"';
		s += ' discript="'+HTMLEncode(temp.discript.value)+'"';
		s += ' valueScript="'+HTMLEncode(temp.valueScript.value)+'"';
		s += ' validateRule="'+HTMLEncode(temp.validateRule.value)+'"';
		s += ' hiddenScript="'+HTMLEncode(temp.hiddenScript.value)+'"';
		s += ' hiddenPrintScript="'+HTMLEncode(temp.hiddenPrintScript.value)+'"';
		s += ' readonlyScript="'+HTMLEncode(temp.readonlyScript.value)+'"';
		s += ' textType="'+HTMLEncode(temp.textType.options[temp.textType.selectedIndex].value)+'"';
		s += ' fieldkeyevent="'+HTMLEncode(temp.fieldkeyevent.options[temp.fieldkeyevent.selectedIndex].value)+'"';
		s += ' fieldtype="'+HTMLEncode(temp.fieldtype.options[temp.fieldtype.selectedIndex].value)+'"';
		s += ' numberPattern="'+HTMLEncode(temp.numberPattern.value)+'"';
	    s += ' processDescription="'+HTMLEncode( createRelStr())+'"';  
		s += ' filtercondition="'+HTMLEncode(temp.filtercondition.value)+'"';  
		s += ' borderType="'+getBorderType()+'"';  
		s += ' authority="'+temp.authority.checked+'"'; 
		s += ' mobile="'+temp.mobile.checked+'"'; 
		var editMode=document.all("editMode");     
	      for(var i=0;i<editMode.length;i++){
			   if(document.all("editMode")[i].checked){
			  	s += ' editMode="'+HTMLEncode( document.all("editMode")[i].value)+'"';
		      }
		    }
		var validateLibs=document.getElementsByName('validateLibs');
		var libs='';
		for(var i=0; i< validateLibs.length; i++){
	   		if(validateLibs[i].checked){
	   			libs+=validateLibs[i].value+";";
	   		}
	   	}
	   	libs=libs.substring(0,libs.length-1);
		s += ' validateLibs="'+HTMLEncode(libs)+'"';   
		s += '>';
	  return s;
	}

	var sAction = URLParams['action'] ;
	var sTitle = "{*[Insert]*}";
	var oControl;
	var oSeletion;
	var sRangeType;
	//oSelection = window.dialogArguments.eWebEditor.document.selection.createRange();
	//sRangeType = window.dialogArguments.eWebEditor.document.selection.type;

	if (sAction == "modify"){
		if (sRangeType == "Control"){
			if (oSelection.item(0).tagName == "INPUT"){
				oControl = oSelection.item(0);
			}
		}else{
			oControl = getParentObject(oSelection.parentElement(), "INPUT");
		}
		if (oControl) {
			sTitle = "{*[Modify]*}";		
		}
	}
	document.write("<title>{*[InputField]*}{*[Property]*}（" + sTitle + "）</title>");

	// 初始值
	function InitDocument(){
		// 修改状态时取值
		var editMode;
		try{
		if (sAction == "modify"){
		   	temp.name.value = HTMLDencode(oControl.name);
			temp.refreshOnChanged.checked = oControl.refreshOnChanged == "true";
			temp.calculateOnRefresh.checked = oControl.calculateOnRefresh == "true";
			temp.borderType.checked = initBorderType(oControl.borderType);
			temp.discript.value = HTMLDencode(oControl.discript);
			temp.valueScript.value = HTMLDencode(oControl.valueScript);
			temp.validateRule.value = HTMLDencode(oControl.validateRule);
			temp.hiddenScript.value = HTMLDencode(oControl.hiddenScript);
			temp.hiddenPrintScript.value = HTMLDencode(oControl.hiddenPrintScript);
			temp.readonlyScript.value = HTMLDencode(oControl.readonlyScript);
			temp.numberPattern.value = HTMLDencode(oControl.numberPattern);
			temp.filtercondition.value =HTMLDencode(oControl.filtercondition);
			temp.authority.checked = oControl.authority == "true";
			temp.mobile.checked = oControl.mobile == "true";
	       

		    editMode=HTMLDencode(oControl.editMode);
		
		    var items=HTMLDencode(oControl.processDescription);
		    parseRelStr(items);
			for(i=0;i<temp.textType.options.length;i++)
				if(temp.textType.options[i].value==HTMLDencode(oControl.textType)){
			    	temp.textType.selectedIndex = i;
					break;
				}
			
			for(i=0;i<temp.fieldkeyevent.options.length;i++)
				if(temp.fieldkeyevent.options[i].value==HTMLDencode(oControl.fieldkeyevent)){
			    	temp.fieldkeyevent.selectedIndex = i;
					break;
			 	}
			 
			for(i=0;i<temp.fieldtype.options.length;i++)
				if(temp.fieldtype.options[i].value==HTMLDencode(oControl.fieldtype)){
			    	temp.fieldtype.selectedIndex = i;
					if (temp.fieldtype.options[i].value == 'VALUE_TYPE_DATE') {
			    		document.all('selectDate').checked = oControl.selectDate == "true"
					}
					break;
				}
			  
			var libstr=HTMLDencode(oControl.validateLibs);
			var lib=libstr.split(';');
			var validateLibs=document.getElementsByName('validateLibs');
		    
		    for(var i=0; i< lib.length; i++){
			    for(var j=0; j< validateLibs.length; j++){
			    	if(validateLibs[j].value==lib[i]){
			    		validateLibs[j].checked=true;
			    	}
		   		}
	   		}
	  	}
		}catch(ex){
			
		}
		ev_onTyepch();
		initForm();
		modeChange(editMode);
	}

function ev_check(){
	   if(temp.name.value==''){
	 	 alert("{*[page.name.notexist]*}");
		  return false;
	   }
	   return !checkStartChar(temp.name.value);
	}

	function checkStartChar(value){
		return IsDigit(value,"{*[page.name.startingit]*}");
	}

	</script>
</head>
<body style="overflow: hidden">
	<form name="temp">
		<table border=0 cellpadding=3 cellspacing=0>
			<tr align=center>
				<td class="card" onclick="cardClick(1)" id="card1">基本</td>
				<td width=2></td>
				<td class="card" onclick="cardClick(2)" id="card2">值脚本</td>
				<td width=2></td>
				<td class="card" onclick="cardClick(3)" id="card3">校验脚本</td>
				<td width=2></td>
				<td class="card" onclick="cardClick(4)" id="card4">隐藏脚本</td>
				<td width=2></td>
				<td class="card" onclick="cardClick(5)" id="card5">打印时隐藏脚本</td>
				<td width=2></td>
				<td class="card" onclick="cardClick(6)" id="card6">只读</td>
			</tr>
			<tr>
				<td align=center valign=middle colspan=11>
				<table border=1 cellpadding=3 cellspacing=1 class="content"
					id="content1">
					<tr>
						<td class="commFont commLabel">名称:</td>
						<td colspan="3"><input type=text name="name" onchange="checkStartChar(this.value);"></td>
					</tr>
					<tr>
						<td class="commFont commLabel">只读:</td>
						<td colspan="3">
							<input type="radio" name="borderType" value="false" checked>只读&nbsp;
							<input type="radio" name="borderType" value="true" >隐藏
						</td>
					</tr>
					<tr>
						<td colspan="4" align="center">
							<input type=checkbox name="refreshOnChanged" value="true">刷新&nbsp;
							<input type=checkbox name="calculateOnRefresh" value="true">重计算&nbsp;
							<input type=checkbox name="mobile" value="true" checked />手机&nbsp;
							<input type=checkbox name="authority" value="true" />权限&nbsp;
						</td>
					</tr>
					<tr>
						<td class="commFont commLabel">描述:</td>
						<td colspan="3"><textarea name="discript" style="width:100%;" rows="7"></textarea></td>
					</tr>
				</table>
				<table border=1 cellpadding=3 cellspacing=1 class="content"
					id="content2">
					<tr>
						<%@include file="commondialog.jsp"%>
					</tr>
				</table>
				<table border=1 cellpadding=3 cellspacing=1 class="content"
					id="content3">
					<tr>
						<td width="25%">
						<table>
							<%
							String applicationid = request.getParameter("application");
						    ValidateRepositoryHelper vrhpler = new ValidateRepositoryHelper();
							Map map = vrhpler.get_validate(applicationid);
								for (Iterator iter = map.keySet().iterator(); iter.hasNext();) {
									Object id = (Object) iter.next();
									String name = (String) map.get(id);
							%>
							<tr>
								<td><input type="checkbox" name="validateLibs"
									value="<%=(String)id %>" /><%=name%></td>
							</tr>
							<%
								}
							%>
						</table>
						</td>
						<td width="75%"><textarea name="validateRule" style="width:100%"
							rows="10"></textarea></td>
					</tr>
				</table>

				<table border=1 cellpadding=3 cellspacing=1 class="content"
					id="content4">
					<tr>
						<td><textarea name="hiddenScript" style="width:100%" rows="10"></textarea></td>
					</tr>
				</table>
				<table border=1 cellpadding=3 cellspacing=1 class="content"
					id="content5">
					<tr>
						<td><textarea name="hiddenPrintScript" style="width:100%" rows="10"></textarea></td>
					</tr>
				</table>
				<table border=1 cellpadding=3 cellspacing=1 class="content"
					id="content6">
					<tr>
						<td><textarea name="readonlyScript" style="width:100%" rows="10"></textarea></td>
					</tr>
				</table>
				</td>
			</tr>
		</table>

</form>

<script language=javascript>
cardClick(1);
</script>
</body>
</o:MultiLanguage>
</html>
